import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

@ManagedBean(name = "mbIntegracao")
@SessionScoped
public class Integracao {
	public Locale locale = new Locale("pt", "BR");
	public ResourceBundle captions;

	public Locale getLocale() {
		return locale;
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}

	public String getRaiz() {
		String raiz = (String) FacesContext.getCurrentInstance()
				.getExternalContext().getRequestContextPath();
		return raiz;
	}

	public void redirect(String pagina) {
		try {
			FacesContext.getCurrentInstance().getExternalContext()
					.redirect(pagina);
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	public void setBrazilLanguage() {
		locale = new Locale("pt", "BR");
		captions = ResourceBundle.getBundle("i18n", locale);

		getSessao().setAttribute("language", captions);

		// teste.trocaIdiomaMenu();
	}

	public void setUSLanguage() {

		locale = new Locale("en", "US");

		// getSessao().setAttribute("language", captions);
		captions = ResourceBundle.getBundle("i18n", locale);
	}

	public HttpSession getSessao() {
		HttpSession sessao = null;

		if (sessao == null) {
			FacesContext facesContext = FacesContext.getCurrentInstance();
			sessao = (HttpSession) facesContext.getExternalContext()
					.getSession(true);
		}

		return sessao;
	}
}
